package com.tron.dobest.schedule;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TronTaskController {
    private  final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private TronTaskRegistrar tronTaskRegistrar;

    @GetMapping("/addTask01")
    public void addTask01(String id) {
        SchedulingRunnable task = new SchedulingRunnable();
        task.setId(id);
        task.setBeanName("tronTaskController");
        task.setMethodName("testTask01");
        task.setParams(null);
        tronTaskRegistrar.addCronTask(task,"0 0 * * * ?");
    }

    @GetMapping("/addTask02")
    public void addTask02(String id) {
        SchedulingRunnable task = new SchedulingRunnable();
        task.setId(id);
        task.setBeanName("tronTaskController");
        task.setMethodName("testTask02");
        task.setParams(new Object[]{"字符串参数",10000});
        tronTaskRegistrar.addCronTask(task,"0 0 * * * ?");
    }

    @GetMapping("/removeTask")
    public void removeTask(String id) {
        tronTaskRegistrar.removeCronTaskById(id);
    }

    public void testTask01() {
        System.out.println("无参的方法执行");
    }

    public void testTask02(String str, Integer i) {
        System.out.println("有参的方法执行，参数："+str+"----"+i);
    }
}
